﻿using Unity.AI.Navigation.Editor;
using UnityEditor;
using UnityEngine;

namespace GameToolkit.Editor
{
    [CanEditMultipleObjects]
    [CustomEditor(typeof(NavMeshModifyVolume), true)]
	public class NavMeshVolumeEditor : VolumeBoundsEditor
	{
        SerializedProperty m_AffectAgents;
        SerializedProperty m_IsRuntime;
        int agentMask;

        protected override void OnEnable()
        {
            base.OnEnable();
            m_AffectAgents = serializedObject.FindProperty("m_AffectAgents");
            m_IsRuntime = serializedObject.FindProperty("m_IsRuntime");
            NavAgentTypeDrawer.GetAgentNames();
            agentMask = NavAgentTypeDrawer.GetAgentMask(m_AffectAgents);
        }

        public override void OnInspectorGUI()
        {
            //EditMode.DoEditModeInspectorModeButton(EditMode.SceneViewEditMode.Collider, "Edit Volume",
            //    EditorGUIUtility.IconContent("EditCollider"), GetBounds, this);
            base.OnInspectorGUI();

            EditorGUI.BeginChangeCheck();
            EditorGUI.BeginDisabledGroup(Application.isPlaying);
            NavMeshComponentsGUIUtility.AgentMaskPopup("Affect Agents", m_AffectAgents);
            //var mask = EditorGUILayout.MaskField("Affect Agents", agentMask, NavAgentTypeDrawer.agentNames);
            //if(mask != agentMask)
            //{
            //    agentMask = mask;
            //    NavAgentTypeDrawer.SetAgentMask(m_AffectAgents, mask);
            //    GUI.changed = true;
            //}
            EditorGUILayout.PropertyField(m_IsRuntime);
            EditorGUI.EndDisabledGroup();
            if(EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }
        }

    }
}